<?php
namespace OT\Builder;

abstract class Builder extends \Think\Controller{

	protected $_type;
	protected $_title;
	protected $_suggest;
	protected $_data = array();
	protected $_keyList = array();

	public function __construct($type){
		parent::__construct();
		$this->_type = $type;
	}

	public function title($title){
		$this->_title = $title;
		$this->meta_title=$title;
		return $this;
	}

	/**
	* suggest  页面标题边上的提示信息
	* @param $suggest
	* @return $this
	*/
	public function suggest($suggest){
		$this->_suggest = $suggest;
		return $this;
	}


	public function data($list){
		$this->_data = $list;
	    return $this;
	}

	public function display($template){
		if ($template) {
			$template = $template;
		}else{
			if($this->_type && MODULE_NAME != 'Admin'){
				$template = T("Common@Builder/".strtolower($this->_type));
			}elseif($this->_type && MODULE_NAME == 'Admin'){
				$template = T("Admin@Builder/admin_".strtolower($this->_type));
			}
		}
		parent::display($template);
	}

	protected function compileHtmlAttr($attr) {
		$result = array();
		foreach($attr as $key=>$value) {
			$value = htmlspecialchars($value);
			$result[] = "$key=\"$value\"";
		}
		$result = implode(' ', $result);
		return $result;
	}
}